﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Gnosis.Babel;
using Gnosis.SQLite.Predicates;
using Gnosis.SQLite.Text;

namespace Gnosis.SQLite
{
    public abstract class TextValue
        : Value, IText
    {
        protected TextValue(string prefix)
            : base(prefix)
        {
        }

        protected TextValue(string prefix, string infix, string postfix)
            : base(prefix, infix, postfix, new List<IExpression>())
        {
        }

        protected TextValue(string prefix, string infix, string postfix, IExpression expression)
            : base(prefix, infix, postfix, new List<IExpression> { expression })
        {
        }

        protected TextValue(string prefix, string infix, string postfix, IList<IExpression> expressions)
            : base(prefix, infix, postfix, expressions)
        {
        }

        #region IText Members

        public ITextColumnName As(string alias)
        {
            return new TextColumnName(ToString(), alias);
        }

        public IPredicate Like(IText value)
        {
            return new Like(this, value);
        }

        public IPredicate NotLike(IText value)
        {
            return new NotLike(this, value);
        }

        public IText Trim()
        {
            return new Trim(this);
        }

        public IText LeftTrim()
        {
            return new LeftTrim(this);
        }

        public IText ToUpper()
        {
            return new ToUpper(this);
        }

        public IText ToLower()
        {
            return new ToLower(this);
        }

        public IText Substring(int start, int length)
        {
            return new Substring(this, new IntegerLiteral(start), new IntegerLiteral(length));
        }

        public IText Concatenate(IText value)
        {
            return new Concatenate(this, value);
        }

        #endregion
    }
}
